package us.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

import us.demo.entity.User;
import us.demo.service.UserService;

@Controller
@RequestMapping(value="/demo")
public class DemoController {
	@Autowired
	private UserService userService;
	
	@RequestMapping("/info")
	public String info(String userId,Model model){
		User user=userService.get(userId);
		model.addAttribute("user", user);
		return "info";
	}
	
	@RequestMapping("/infoJson")
	public @ResponseBody JSONObject infoJson(String userId,Model model){
		User user=userService.get(userId);
		JSONObject jsonObject=new JSONObject();
		jsonObject.put("id", user.getId());
		jsonObject.put("name", user.getName());
		jsonObject.put("sex", user.getSex());
		jsonObject.put("password", user.getPassword());
		return jsonObject;
	}
}
